/**
 * @param {string} s
 * @return {number}
 */
var myAtoi = function (s) {
  s = s.trimStart(' ')
  let res = ''
  let flag = 1
  if (s[0] == '-' || s[0] == '+') {
    flag = s[0] == '-' ? 0 : 1
    s = s.slice(1)
  }
  s = s.trimStart(0)
  // console.log(s);
  for (const c of s) {

    if (!isNaN(c) && c!=' ') {
      if (res == '' && c!='0') {
          res += c
       
      }
      if(res != '')
        res += c
      
    } else break
  }
  if (!flag) res = 0 - Number(res)
  if (res > Math.pow(2, 31) - 1) {
    res = Math.pow(2, 31) - 1
  }
  if (res < -Math.pow(2, 31)) {
    res = -Math.pow(2, 31)
  }
  return res ? res : 0
}
// console.log(!isNaN(' '));
console.log(myAtoi("   +0 123"))
